<template>
	<template-tab v-if="dataList?true:false" :dataList="dataList" :parameter="parameter" @changeTab="changeTab">
	</template-tab>
</template>

<script>
	import templateTab from '@/pagecomponents/templateTab/index.vue'
	export default {
		components: {
			'template-tab': templateTab
		},
		data() {
			return {
				dataList: null, // null表示未初始化或需要重新初始化
				parameter: null,
			};
		},
		props: ["templateItem"],
		watch: {
			templateItem: {
				handler(item) {
					if (item.code) {
						this.init(item);
					}
				},
				immediate: true
			}
		},
		methods: {
			changeTab(obj) {
				let {
					index,
					item,
					currentIndex
				} = obj
				if (this.parameter.searchVal == 'multiLevel') {
					this.$emit('relationSearch', {
						relation: this.parameter.relation,
						params: {
							one_type: item.one_type,
							two_type: item.two_type
						}
					});
				} else if (currentIndex !== index && this.parameter.searchVal) {
					this.$emit('relationSearch', {
						relation: this.parameter.relation,
						params: {
							[this.parameter.searchVal]: item.value
						}
					});
				}
			},
			init(item) {
				this.parameter = {
					...item.parameter
				}
				this.dataList = [].concat(item.pageData || [])
			}
		}
	};
</script>

<style lang="scss" scoped>

</style>
